Sort character by frequency#7391
Sort character by frequency#7391lieutenant-Rohit wants to merge 5 commits intoTheAlgorithms:masterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7391 +/- ##
============================================
+ Coverage 79.53% 79.55% +0.02%
- Complexity 7176 7184 +8
============================================
Files 798 799 +1
Lines 23467 23486 +19
Branches 4617 4621 +4
============================================
+ Hits 18665 18685 +20
Misses 4055 4055
+ Partials 747 746 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
felseje
left a comment
There was a problem hiding this comment.
I went through the Checkstyle findings and left some comments to help guide the necessary changes.
| int diff = b.getValue() - a.getValue(); | ||
|
|
||
| // If frequency same, sort by character | ||
| if (diff == 0) return a.getKey() - b.getKey(); |
There was a problem hiding this comment.
Instead of using a single-line if statement like:
if (diff == 0) return a.getKey() - b.getKey();
please use braces:
if (diff == 0) {
return a.getKey() - b.getKey();
}
| @@ -0,0 +1,66 @@ | |||
| // Reference: https://leetcode.com/problems/sort-characters-by-frequency/ | |||
| package com.thealgorithms.strings; | |||
| import java.util.*; | |||
There was a problem hiding this comment.
Avoid using wildcard imports (e.g., java.util.*). Please import only the specific classes you need.
| @@ -0,0 +1,49 @@ | |||
| package com.thealgorithms.strings; | |||
|
|
|||
| import static org.junit.jupiter.api.Assertions.*; | |||
There was a problem hiding this comment.
Avoid using wildcard imports (e.g., org.junit.jupiter.api.Assertions.*). Please import only the specific classes you need.
Added SortCharacterByFrequency algorithm using HashMap and Priority Queue